package com.xbx.zuul.config.mvc;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import java.util.Arrays;

/**
 * 跨域处理
 *
 * @author 89005691
 * @create 2018-09-26 12:30
 */

@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {

    @Value("${mvcCorsHost}")
    private String mvcCorsHost;

    @Override
    public void addCorsMappings(CorsRegistry registry) {

        registry.addMapping("/**")
                .allowedOrigins(mvcCorsHost.split(","))
                .allowCredentials(true)
                .allowedMethods("*")
                .allowedHeaders("*").allowCredentials(true)
                .maxAge(3600);
    }
}
